package com.huiquan.framework.utils;

import java.nio.charset.Charset;
import java.util.ArrayList;

import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;

public class CsvUtil {
	public static ArrayList<String[]> readeCsv(String csvFilePath) throws Exception {
		ArrayList<String[]> csvList = new ArrayList<String[]>(); // 用来保存数据
		CsvReader reader = new CsvReader(csvFilePath, ',', Charset.forName("UTF-8")); // 一般用这编码读就可以了

		while (reader.readRecord()) { // 逐行读入数据
			csvList.add(reader.getValues());
		}
		reader.close();
		return csvList;
	}
	
	// 用到的时候再改
	public void writeCsv() throws Exception {
		String csvFilePath = "c:/test.csv";
		CsvWriter wr = new CsvWriter(csvFilePath, ',', Charset.forName("SJIS"));
		String[] contents = { "aaaaa", "bbbbb", "cccccc", "ddddddddd" };
		wr.writeRecord(contents);
		wr.close();
    }
}
